package com.blogsoho.taurus.dao.mapper;

import com.blogsoho.taurus.dao.builder.ContentSqlBuilder;
import com.blogsoho.taurus.vo.ContentVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by 16978 on 2017/6/10.
 */
public interface ContentMapper {

    @InsertProvider(type = ContentSqlBuilder.class, method = "addContent")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public int addContent(ContentVO vo);

    @SelectProvider(type = ContentSqlBuilder.class, method = "getAllContent")
    @Results(id = "content", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "created", column = "created"),
            @Result(property = "title", column = "title"),
            @Result(property = "text", column = "text"),
            @Result(property = "markdownText", column = "markdown_text"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "parentId", column = "parent_id"),
            @Result(property = "summary", column = "summary")

    })
    public List<ContentVO> getAllContent(@Param("start") int start, @Param("length") int length);

    @SelectProvider(type = ContentSqlBuilder.class, method = "getCountContent")
    public int getCountContent();

    @SelectProvider(type = ContentSqlBuilder.class, method = "getContentById")
    @ResultMap("content")
    public ContentVO getContentById(@Param("id") Integer id);

    @UpdateProvider(type = ContentSqlBuilder.class, method = "updateContent")
    public int updateContent(ContentVO vo);

    @SelectProvider(type = ContentSqlBuilder.class, method = "getContentByCategoryId")
    @ResultMap("content")
    public List<ContentVO> getContentByCategoryId(@Param("id") Integer id);
}
